home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / patch / ttx-topscreen.lha / Source / TopScreen.c < prev   
Encoding:
C/C++ Source or Header  |  1994-12-04  |  1.4 KB  |  72 lines

  1. /* TopScreen:    Print the name of the topmost screen if it is public.
  2.  *        If it is not public, print "Workbench".
  3.  *
  4.  * Author:    Daniel J. Barrett, barrett@cs.umass.edu
  5.  *         Public Domain
  6.  */
  7.  
  8. char *Version = "$VER: TopScreen 1.1 (3.12.94)";
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/intuitionbase.h>
  16. #include <intuition/screens.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19.  
  20. #define    DEFAULT_SCREEN    "Workbench"
  21.  
  22. UBYTE *GetPubName(struct Screen *scr);
  23.  
  24. struct IntuitionBase *IntuitionBase;
  25.  
  26. VOID main(int argc, char **argv)
  27. {
  28.     struct Screen *scr;
  29.  
  30.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
  31.     if (!IntuitionBase)
  32.         exit(1);
  33.  
  34.     scr = IntuitionBase->FirstScreen;
  35.     if (!scr)
  36.         puts(DEFAULT_SCREEN);
  37.     else
  38.         puts(GetPubName(scr));
  39.  
  40.     if (IntuitionBase)
  41.         CloseLibrary((struct Library *)IntuitionBase);
  42. }
  43.  
  44.  
  45. UBYTE *GetPubName(struct Screen *scr)
  46. {
  47.     struct List *list;
  48.     struct Node *pubs;
  49.     struct PubScreenNode *psn;
  50.     static UBYTE name[MAXPUBSCREENNAME+1];
  51.  
  52.     strcpy(name, DEFAULT_SCREEN);
  53.  
  54.     if ((list = LockPubScreenList()) != NULL)
  55.     {
  56.  
  57.         for (pubs = list->lh_Head; pubs->ln_Succ; pubs = pubs->ln_Succ)
  58.         {
  59.             psn = (struct PubScreenNode *)pubs;
  60.             if (scr == psn->psn_Screen)
  61.             {
  62.                 strcpy(name, pubs->ln_Name);
  63.                 break;
  64.             }
  65.         }
  66.  
  67.         UnlockPubScreenList();
  68.     }
  69.  
  70.     return(name);
  71. }
  72.